package proxy;

/**
 * 代理类.
 *
 * @author GongXincheng
 * @since 2019-09-17 15:08
 */
public class Proxy implements Subject {

    private RealSubject realSubject;

    @Override
    public synchronized void speak(String message) {
        if (realSubject == null) {
            realSubject = new RealSubject();
        }
        realSubject.speak(message);
    }

    @Override
    public synchronized void run() {
        if (realSubject == null) {
            realSubject = new RealSubject();
        }
        realSubject.run();
    }

    @Override
    public synchronized void sing() {
        if (realSubject == null) {
            realSubject = new RealSubject();
        }
        realSubject.sing();
    }
}
